<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Vue-plugin-hiprint Demo</title>
    <!-- 引入Vue.js和Vue-plugin-hiprint插件 -->
    <script src="https://cdn.jsdelivr.net/npm/vue@2"></script>
    <script src="https://unpkg.com/vue-plugin-hiprint"></script>
    <!-- 引入Bootstrap样式，用于网格布局 -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
</head>
<body>
<div id="app" class="container mt-5">
    <h1>Vue-plugin-hiprint Demo</h1>
    <button @click="printGrid">Print Grid</button>
</div>

<!-- Vue.js模板 -->
<script type="text/x-template" id="grid-template">
    <div>
        <h2>Printable Grid</h2>
        <table class="table table-bordered no-background">
            <thead>
            <tr>
                <th v-for="column in columns">{{ column }}</th>
            </tr>
            </thead>
            <tbody>
            <tr v-for="(row, index) in rows" :key="index">
                <td v-for="column in columns">{{ row[column] }}</td>
            </tr>
            </tbody>
        </table>
    </div>
</script>

<!-- 自定义样式 -->
<style>
    /* 自定义样式，用于关闭网格背景 */
    .no-background {
        background-color: transparent !important;
    }
</style>

<script>
    // 注册Vue插件
    Vue.use(VuePluginHiPrint);

    new Vue({
        el: '#app',
        data: {
            // 模拟网格数据
            gridData: [
                { id: 1, name: 'John', age: 30 },
                { id: 2, name: 'Jane', age: 25 },
                { id: 3, name: 'Doe', age: 40 }
            ]
        },
        methods: {
            printGrid() {
                // 打印网格内容
                this.$hiPrint({
                    content: '#grid-template', // 使用id选择器来指定要打印的内容
                    data: {
                        columns: ['id', 'name', 'age'], // 列名
                        rows: this.gridData // 行数据
                    }
                });
            }
        }
    });
</script>
</body>
</html>
